package com.blacktea.behavioralpatterns.commandpattern;

import org.springframework.stereotype.Component;

/**
 * @description: 文本编辑器
 * @author: black tea
 * @date: 2023/3/24 20:20
 */
@Component
public class Editor {

    private final CommandExecutor executor = new CommandExecutor();
    private final StringBuilder content = new StringBuilder();

    public void add(String text, int start) {
        content.insert(start, text);
    }

    public void delete(int start, int end) {
        content.delete(start, end);
    }

    public void execute(Command command) {
        executor.executeCommand(command);
    }

    public void undo() {
        executor.undoCommand();
    }

    public String getContent() {
        return content.toString();
    }
}
